home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / rexx / dofile34.lha / dofile / dofile.rexx < prev    next >
OS/2 REXX Batch file  |  1997-08-15  |  3KB  |  131 lines

  1. /*
  2. ** $VER: dofile.rexx 3.4 (15.8.97) Rolf Rotvel
  3. **
  4. ** Uses datatypes.library & rexxreqtools.library
  5. */
  6.  
  7. defdir = 'txt:'                                 /* Defdir for filerequester */
  8. multicmd = 'sys:utilities/multiview screen'     /* Path (& options) to Multiview */
  9.  
  10. /*
  11. ** End cfg.
  12. */
  13.  
  14. /* Load libraries */
  15. call addlib('rexxsupport.library', 0, -30, 0)
  16. call addlib('rexxreqtools.library', 0, -30, 0)
  17. call addlib('datatypes.library', 0, -30)
  18.  
  19. /* Get version info from $VER line */
  20. version = subword(sourceline(2), 3, 2) 
  21.  
  22. /* If no arg then open filerequester */
  23. if arg() = 0 then do
  24.     /* Check defdir */
  25.     if ~exists(defdir) | defdir = '' then defdir = pragma('d')
  26.     /* Get file or dir */
  27.     txt = gettxt(defdir)
  28. end
  29. else txt = strip(arg(1), 'b', '"')  /* Get args and remove any quotes */
  30.  
  31. /* Is it a lone .info file? */
  32. if ~exists(txt) then do
  33.     txt2 = txt||'.info'
  34.     if exists(txt2) then txt = txt2
  35.     else do
  36.         errtxt = 'File error'
  37.         call syntax()
  38.     end
  39. end
  40.  
  41. /* Get (data)type of file */
  42. errtxt = 'datatypes.library error'
  43. type = getfiletype(txt)
  44.  
  45. /* Open filerequester if it's a directory? */
  46. if type = 'DIRECTORY' then type = getfiletype(gettxt(txt))
  47.  
  48. /* Get command associated with filetype */
  49. cmd = getclip('dofile.'||type)
  50.  
  51. /* Check ascii & binary files for file extensions */
  52. select 
  53.     when type = 'ASCII' then do
  54.         cmd = getcmd(txt)
  55.         /* Let Multiview do the job on ascii files if no cmd */
  56.         if cmd = '' then cmd = multicmd
  57.     end
  58.     when type = 'BINARY' then cmd = getcmd(txt)
  59.     otherwise do     
  60.         /* It's a known datatype so Multiview should work */        
  61.         if cmd = '' then cmd = multicmd
  62.     end
  63. end
  64.  
  65. errtxt = 'Couldn''t process'
  66. if cmd = '' then call syntax()
  67.  
  68. if right(cmd, 2) = '->' then do
  69.     /* Concatate file with last word of command */
  70.     parse var cmd cmd '->' .
  71.     errtxt = cmd||' error'
  72.     w = words(cmd)
  73.     cmd = subword(cmd, 1, w - 1)||' "'||subword(cmd, w, 1)||txt||'"'
  74. end
  75. else do
  76.     errtxt = cmd||' error'
  77.     cmd = cmd||' "'||txt||'"'
  78. end
  79.  
  80. say realtype||' -> '||cmd
  81. signal on failure
  82. address command cmd
  83. exit
  84.  
  85.  
  86. GETCMD: procedure expose cmd type
  87. arg path
  88. newcmd = ''
  89.  
  90. /* Extract file extension from path */
  91. parse value substr(path, max(pos(':', path), lastpos('/', path)) + 1) with base '.' suff
  92.  
  93. if suff ~= '' then do   /* Filename has an extension */
  94.     newcmd = getclip('dofile..'||suff)
  95.     if newcmd ~= '' then type = '.'||suff
  96.     else do             /* No match > check base for MOD. type names */
  97.         newcmd = getclip('dofile..'||base)
  98.         if newcmd ~= '' then type = '.'||base
  99.     end
  100.     if newcmd ~= '' then cmd = newcmd
  101. end
  102. return cmd
  103.  
  104.  
  105. /* Get argument from filereq - exit if none */
  106. GETTXT:
  107. txt = rtfilerequest(arg(1),, version,, 'rt_screentofront=true')
  108. if txt = '' then exit
  109. return strip(txt, 'b', '"')
  110.  
  111.  
  112. GETFILETYPE: 
  113. /* Error handling for datatypes.library v40.6 */
  114. signal on syntax
  115. realtype = examinedt(arg(1),, var)
  116. signal off syntax
  117.  
  118. /* Error handling for datatypes.library v45.3 */
  119. if datatype(realtype, 'w') then call syntax()
  120.  
  121. return upper(strip(realtype, 't', '0'x))
  122.  
  123.  
  124. SYNTAX:
  125. call rtezrequest(errtxt||':'||'0a'x||txt,, version)
  126. exit
  127.  
  128.  
  129. FAILURE:
  130. exit
  131.